﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace cjwygl
{
    public partial class FrmControlPanel : Form
    {
        public FrmControlPanel()
        {
            InitializeComponent();
        }

        private void FrmControlPanel_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void button_opmgr_Click(object sender, EventArgs e)
        {
            FrmOpMgr frmOpr = new FrmOpMgr();
            frmOpr.ShowDialog();
        }

        private void FrmControlPanel_Load(object sender, EventArgs e)
        {
            button_opmgr.Enabled = false;
            button_rolemgr.Enabled = false;
            if (userinfo.hasPermission("opmgr"))
                button_opmgr.Enabled = true;
            if (userinfo.hasPermission("rolemgr"))
                button_rolemgr.Enabled = true;
            LoadAlertInfo();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //printDocument1.Print();
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
        }

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            Font titleFont = new Font("宋体", 9, FontStyle.Bold);//标题字体            
            Font fntTxt = new Font("宋体", 9, FontStyle.Regular);//正文文字            
            Brush brush = new SolidBrush(Color.Black);//画刷            
            Pen pen = new Pen(Color.Black);           //线条颜色            
            Point po = new Point(10, 10);
            try
            {
                
                e.Graphics.DrawString(GetPrintSW().ToString(), titleFont, brush, po);   //DrawString方式进行打印。         
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "打印出错！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public StringBuilder GetPrintSW()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("                              付款通知单                              ");
            sb.AppendLine("户名：大商条码                        房间号：806                       ");
            sb.AppendLine("--------------------------------------------------------------------");
            sb.AppendLine("费用名称        结算日期          金额                  备注             ");
            sb.AppendLine(" 房租        12.7.1-12.7.31    2800                                  ");
            sb.AppendLine("物业费       12.7.1-12.7.31     416");
            sb.AppendLine("网络         12.7.1-12.7.31     150");
            sb.AppendLine("车位费       12.7.1-12.7.31     150");
            sb.AppendLine("小计：                          3516");
            sb.AppendLine("电费         12.7.1-12.7.31     108.3             抄表数：12139");
            sb.AppendLine("合计                            3624.3");
            sb.AppendLine("-------------------------------------------------------------------");
            sb.AppendLine("请在接到此通知后一周内付款，逾期将根据合同条款收取2‰滞纳金。");
            sb.AppendLine("                                          交大科技园海科园区");
            sb.AppendLine("                                              2012.7.1");



            return sb;   
        }

        private void button_customermgr_Click(object sender, EventArgs e)
        {
            FrmCustomerMgr frmCustomer = new FrmCustomerMgr();
            frmCustomer.Show();
            frmCustomer.WindowState = FormWindowState.Maximized;
            this.WindowState = FormWindowState.Minimized;
        }

        private void button_refresh_Click(object sender, EventArgs e)
        {
            LoadAlertInfo();

        }
        private void LoadAlertInfo()
        {
            webBrowser1.DocumentText = "<div style='font-weight: bolder; font-size: large; color: #FF0000'>"+
"以下商户合同即将到期：</div><table style='width: 100%;'>"+
"<tr><td>&nbsp;公司名称</td><td>合同号</td><td>合同起始日期</td><td>"+
"合同终止日期</td><td>联系人</td><td>联系电话</td></tr><tr><td>公司一</td>"+
"<td>189</td><td>2011-12-01</td><td>2013-7-31</td><td>陈某某</td><td>"+
"13688899999</td></tr><tr><td>公司二</td><td>190</td><td>2009-12-01</td>"+
"<td>2013-7-31</td><td>周某某</td><td>18018288888</td></tr></table>"+
"<div style='font-weight: bolder; font-size: large; color: #FF0000'>"+
"七月付款通知单尚未打印</div>" +
"<div style='font-weight: bolder; font-size: large; color: #FF0000'>" +
"以下商户合同已过期</div><table style='width: 100%;'>"+
"<tr><td>&nbsp;公司名称</td><td>合同号</td><td>合同起始日期</td><td>"+
"合同终止日期</td><td>联系人</td><td>联系电话</td></tr><tr><td>公司三</td>"+
"<td>191</td><td>2011-12-01</td><td>2013-7-1</td><td>陈某某</td><td>"+
"13688899999</td></tr><tr><td>公司四</td><td>192</td><td>2009-12-01</td>"+
"<td>2013-7-1</td><td>周某某</td><td>18018288888</td></tr></table>";

        }


        private void button_print_Click(object sender, EventArgs e)
        {
            //printPreviewDialog1.Document = printDocument1;
            //printPreviewDialog1.Show();
            FrmPrint frmPrint = new FrmPrint(DateTime.Now.ToString("yyyyMM"), 0);
            frmPrint.ShowDialog();
        }

        private void button_rolemgr_Click(object sender, EventArgs e)
        {
            FrmRoleMgr frmMgr = new FrmRoleMgr();
            frmMgr.Show();
        }

        private void button_feemgr_Click(object sender, EventArgs e)
        {
            FrmFeeMgr feeMgr = new FrmFeeMgr();
            feeMgr.ShowDialog();
        }

    }
}
